import java.util.Stack;


public class Rule {

	private Stack<Literal> left;
	private Stack<Literal> right;
	
	public Rule() {
		this.left = new Stack<Literal>();
		this.right = new Stack<Literal>();
	}
	
	public Rule(Rule rule) {
		if (rule == null)
		{
			this.left = new Stack<Literal>();
			this.right = new Stack<Literal>();
			return;
		}
		
		this.left = new Stack<Literal>();
		
		for (Literal lit : rule.getLeftLiteral()) 
		{
			Literal tmp_lit = new Literal(lit.getName(), new Atom[lit.getArgv().length]);
			for (int i = 0; i < lit.getArgv().length; i++) 
			{
				tmp_lit.getArgv()[i] = new Atom(lit.getArgv()[i].getVarname());
			}
			
			this.left.add(tmp_lit);
		}
		
		this.right = new Stack<Literal>();
		
		for (Literal lit : rule.getRightLiteral()) 
		{
			Literal tmp_lit = new Literal(lit.getName(), new Atom[lit.getArgv().length]);
			for (int i = 0; i < lit.getArgv().length; i++) 
			{
				tmp_lit.getArgv()[i] = new Atom(lit.getArgv()[i].getVarname());
			}
			
			this.right.add(tmp_lit);
		}
	}

	public void addLeftLiteral(Literal literal){
		this.left.add(literal);
	}
	
	public void addRightLiteral(Literal literal){
		this.right.add(literal);
	}
	
	public Literal popLeftLiteral() {
		return this.left.pop();
	}

	public Literal popRightLiteral() {
		if(this.right.size() > 0)
			return this.right.pop();
		return null;
	}
	
	public Stack<Literal> getLeftLiteral()
	{
		return this.left;
	}
	
	public Stack<Literal> getRightLiteral()
	{
		return this.right;
	}
	
	@Override
	public String toString() {
		return left.toString() + " :- " + right.toString();
	}
}
